package com.rdc.qingkou.presenter;

import android.content.Context;

import com.rdc.qingkou.base.BasePresenterImpl;
import com.rdc.qingkou.contract.LaunchContract;
import com.rdc.qingkou.model.LaunchModel;
import com.rdc.qingkou.model.LoginModel;
import com.rdc.qingkou.model.imodel.ILoginCallBack;
import com.rdc.qingkou.utils.DirectedLoginUtil;
import com.rdc.qingkou.utils.ToastUtil;


public class LaunchPresenter extends BasePresenterImpl<LaunchContract.View> implements LaunchContract.PrestenerI {
    private LaunchModel mLaunchModel = new LaunchModel();
    private LoginModel mLoginModel = new LoginModel();


    @Override
    public void jumpToLogin() {
       mView.jumpToLogin();
    }

    @Override
    public void jumpToRegister() {
       mView.jumpToRegister();
    }

    @Override
    public void jumpToWelcome() {
        if (mLaunchModel.isWelcomed((Context)mView)==false){
            mView.jumpToWelcome();
        }else{
            if (DirectedLoginUtil.checkIsLogined()==true){
                mLoginModel.LoginRequest(DirectedLoginUtil.getAccount(), DirectedLoginUtil.getPassword(), new ILoginCallBack() {
                    @Override
                    public void onSuccess() {
                        mView.jumpToHomepage();
                    }

                    @Override
                    public void onFail(String reason) {
                        ToastUtil.showToastMessage(reason);

                        if (reason.equals("对不起，登录信息出错！请重新登录")){
                            mView.jumpToLogin();
                        }

                    }
                });
        }

        }
    }

    @Override
    public void setWelcomed() {
         mLaunchModel.setWelcomed((Context) mView);
    }
}
